# -*- coding: UTF-8 -*-
import requests,re
import random
from bs4 import BeautifulSoup

def save_image(img):
	random_int = random.randint(0, 10000)
	img_name = str(random_int)+img.split('/')[-1]
	print 'begin save :' + img
	final_img = requests.get(img)
	f = open('/root/img/'+img_name, 'ab')
	f.write(final_img.content)
	print(img_name, 'save success!')

url = 'http://fj.sina.com.cn/news/'
r = requests.get(url)

imgs_srcs = []
soup = BeautifulSoup(r.text, 'lxml')
imgs = soup.find_all('img')
#print imgs

for img in imgs:
	imgs_srcs.append(img['src'])

imgs_srcs = list(set(imgs_srcs))
for img in imgs_srcs:
	if re.match(r'^http', img):
		save_image(img)
